"""
In-memory storage implementation
"""

"""
    MemoryStorage

Stores simulation data in memory for quick access.
"""
mutable struct MemoryStorage
    data::Dict{Float64, Any}
    times::Vector{Float64}
    
    MemoryStorage() = new(Dict{Float64, Any}(), Float64[])
end

function save_field(storage::MemoryStorage, field, time::Float64)
    storage.data[time] = deepcopy(field)
    if !(time in storage.times)
        push!(storage.times, time)
        sort!(storage.times)
    end
end

function load_field(storage::MemoryStorage, time::Float64)
    if haskey(storage.data, time)
        return storage.data[time]
    else
        throw(KeyError("Time $time not found in storage"))
    end
end

function get_time_series(storage::MemoryStorage)
    return copy(storage.times)
end

Base.length(storage::MemoryStorage) = length(storage.times)